supernova: fix for small audio vector sizes
[supercollider.git] / examples / demonstrations / more graphs.scd
blob6e6763c38908a73032cff9238a6ecde4fe253967
1 Server.local.boot;
5 SynthDef("bubbles", {
6         var f, zout;
7         f = LFSaw.kr(0.4, 0, 24, LFSaw.kr([8,7.23], 0, 3, 80)).midicps; // glissando function
8         zout = CombN.ar(SinOsc.ar(f, 0, 0.04), 0.2, 0.2, 4); // echoing sine wave
9         Out.ar(0, zout.postln);
10 }).add;
12 SynthDef("moto-rev", {
13         var x;
14         x = RLPF.ar(LFPulse.ar(SinOsc.kr(0.2, 0, 10, 21), [0,0.1], 0.1), 100, 0.1).clip2(0.4);
15         Out.ar(0, x);
16 }).add;
18 SynthDef("thru", { arg out, gate=1;
19         var zin, zout, env;
20         env = Linen.kr(gate, 2, 1, 2);
21         XOut.ar(out, env, ClipNoise.ar([0.1,0.1]));
22         FreeSelfWhenDone.kr(env);
23 }).add;
25 SynthDef("wah", { arg out, rate = 1.5, cfreq = 1400, mfreq = 1200, rq=0.1, wet=1, gate=1;
26         var zin, zout, env;
27         zin = In.ar(out, 2);
28         cfreq = Lag3.kr(cfreq, 0.1);
29         mfreq = Lag3.kr(mfreq, 0.1);
30         env = Linen.kr(gate, 1, 1, 1);
31         wet  = Ramp.kr(wet, 0.1);
32         rq   = Ramp.kr(rq, 0.1);
33         zout = RLPF.ar(zin, LFNoise1.kr(rate, mfreq, cfreq), rq, 10).distort * 0.15;
34         XOut.ar(out, wet * env, zout);
35         FreeSelfWhenDone.kr(env);
36 }).add;
38 SynthDef("combdist", { arg out, freq = 400, decay=2, wet=1, gate=1;
39         var zin, zout, env;
40         zin = In.ar(out, 2);
41         freq = Lag3.kr(freq, 0.1);
42         env = Linen.kr(gate, 1, 1, 1);
43         wet  = Ramp.kr(wet, 0.1);
44         zout = CombN.ar(zin, 24.midicps.reciprocal, freq.reciprocal, decay).distort.reverse; 
45         XOut.ar(out, wet * env, zout);
46         FreeSelfWhenDone.kr(env);
47 }).add;
49 SynthDef("echo", { arg out, maxdelay = 0.5, delay = 0.4, decay=3, wet=1, gate=1;
50         var zin, zout, env;
51         zin = In.ar(out, 2);
52         delay = Lag3.kr(delay, 0.1);
53         env = Linen.kr(gate, 1, 1, 1);
54         wet  = Ramp.kr(wet, 0.1);
55         zout = CombN.ar(zin * env, maxdelay, delay, decay).reverse; 
56         XOut.ar(out, wet * env, zout);
57         FreeSelfWhenDone.kr(env);
58 }).load(s);
60 SynthDef("reverb", { arg out, decay=6, wet=1, gate=1;
61         var zin, zout, env;
62         zout = In.ar(out, 2);
63         env = Linen.kr(gate, 0.1, 1, 0.1);
64         wet = Ramp.kr(wet, 0.1);
65         decay = Ramp.kr(decay, 0.1);
66         8.do({ 
67                 zout = AllpassN.ar(zout, 0.04, {Rand(0.001,0.04)}.dup, decay) 
68         });
69         XOut.ar(out, wet * env, zout);
70         FreeSelfWhenDone.kr(env);
71 }).load(s);
73 SynthDef("ring-mod", { arg out, freq=800, wet=1, gate=1;
74         var zin, zout, env;
75         freq = Ramp.kr(freq, 0.1);
76         env = Linen.kr(gate, 1, 1, 1);
77         wet  = Ramp.kr(wet, 0.1);
78         zin = In.ar(out, 2);
79         zout = zin * SinOsc.ar(freq, [0,0.5pi]);
80         XOut.ar(out, wet * env, zout);
81         FreeSelfWhenDone.kr(env);
82 }).add;
87 a = sqrt(1 - b.squared);
88 XFadeOut.ar(chan, xfade, outs)
90 fade in an effect, fade out an effect.
92 simple mix architecture:
93 8 stereo inputs with gain & balance.
94 4 insert fx per input with 4 params each.
95 4*4*8
97 groups:
98         control group
99         voice group
100         fx group
101         mixer
105 SynthDef("mixer3", {
106         var channels, faders, master;
107         channels = In.ar(4, 16).clump(2);
108         master = Ramp.kr(In.kr(0, 1), 0.05);
109         faders = Ramp.kr(In.kr(1, 8), 0.05);
110         Out.ar(0, Mix(channels * faders) * master);
111 }).add;
113 SynthDef("line", { arg out, start=1, end=0, dur=3;
114         var line;
115         line = Line.kr(start, end, dur);
116         ReplaceOut.kr(out, line);
117         FreeSelfWhenDone.kr(line);
118 }).add;
120 SynthDef("xline", { arg out, start=1, end=0.0001, dur=3;
121         var line;
122         line = XLine.kr(start, end, dur);
123         Out.kr(out, line);
124         FreeSelfWhenDone.kr(line);
125 }).add;
127         
132 //patch a control to read from a bus.
134 //gradually change a parameter over some period.
138         var server;
139         server = Server.local;  
141         d = 0.04;
142         r = Routine({
143                 
144                 3.do({  
145                                         
146                 0.5.postln.wait;
147                 
148                 server.sendBundle(d, ["/s_new", "moto-rev", 1000, 0]);
149                 
150                 3.wait;
152                 //server.sendBundle(d, ["nod.free", 1000]);
153                 
154                 
155                 server.sendMsg("/n_free", 1000);
156                 1.wait;
157                 });
158                                                 
159         });
160         SystemClock.play(r);
164         d = 0.05;
165         r = Routine({
166                 var server;
167                 server = Server.local;  
168                 
169                 1.do({
170                                                 
171                         0.5.postln.wait;
172                         
173                         server.sendBundle(d, ["/s_new", "bubbles", 1000, 0].postln);
174         
175                         // add effects, each one (processing order) after the previous one
176                         4.wait;
177                         server.sendBundle(d, ["/s_new", "combdist", 1004, 3,1000, \freq, rrand(24,60).midicps].postln);
178                         4.wait;
179                         server.sendBundle(d, ["/s_new", "wah", 1001, 3,1004].postln);
180         
181                         4.wait;
182                         server.sendBundle(d, ["/s_new", "echo", 1002, 3, 1001,\delay, 0.2, \decay, 4].postln);
183         
184                         4.wait;
185                         server.sendBundle(d, ["/s_new", "ring-mod", 1003, 3,1002, \delay, 0.2, \decay, 4].postln);
186                         
187                         12.wait;
189                         // release the gates by setting them to 0, allowing synths to die
190                         server.sendBundle(d, ["/n_set", 1004, "gate", 0].postln);
191                         
192                         4.wait;
193                         server.sendBundle(d, ["/n_set", 1001, "gate", 0].postln);
194         
195                         4.wait;
196                         server.sendBundle(d, ["/n_set", 1002, "gate", 0].postln);
197         
198                         4.wait;
199                         server.sendBundle(d, ["/n_set", 1003, "gate", 0].postln);
200         
201                         4.wait;                 
202                         server.sendBundle(d, ["/n_free", 1000].postln);
203                         1.wait;                 
204         
205                         server.sendBundle(d, ["/g_freeAll", 0].postln);
206                 });
207                                         
208                 1.wait;
209                 
210         });
211         SystemClock.play(r);
214 // default node def not written
215 //f = { arg o; Pbind(\note, Pxrand([0,2,3,5,7,9,10,12],inf), \octave, o, \dur, 0.25) };
216 //Ppar([f.value(7),f.value(6), f.value(5)]).play(Event.protoEvent)
218 Server.default.sendMsg("/notify", 1);
220 SynthDef("default", { arg freq=440, gate=1, amp=0.2;
221         var e, s;
222         e = EnvGen.kr(Env.linen(0.004,amp,0.5), gate);
223         FreeSelfWhenDone.kr(e);
224         s = SinOsc.ar(freq,0, e);
225         Out.ar(0, s);
226 }).add;